<?php
/**
 * 商品属性
 * @author maniac
 */
namespace app\common\service;

use app\common\model\GoodAttrs AS GoodAttrsModel;

class GoodAttrs extends Base
{
    /**
     * 获取商品属性
     * @param  string $attr_ids 商品属性 id
     */
    public function attrs($attr_ids)
    {
        $where = [
            ['id', 'in', $attr_ids],
        ];
        $attrs = GoodAttrsModel::field('id,name,show_type,value')->where($where)->order('list_order DESC,id ASC')->select();
        $data  = [];
        foreach ($attrs as $attr) {
            $value = '';
            if ($attr['show_type'] == 2 || $attr['show_type'] == 3) {
                $value = explode("\r\n", $attr['value']);
            }
            $attr['value'] = $value;
            $data[] = $attr;
        }
        return $data;
    }
}
